// 路由配置
import Layout from "@/pages/Layout/index";
import Login from "@/pages/Login/index";

import { createBrowserRouter } from "react-router-dom";
import { AuthRoute } from "@/components/AuthRoute";
// import Home from "@/pages/Home";
// import Article from "@/pages/Article";
// import Publish from "@/pages/Publish";
import {lazy, Suspense} from "react";

// 1. lazy函数对组件进行导入--路由懒加载
const Home = lazy(() => import('@/pages/Home/index'))
const Article = lazy(() => import('@/pages/Article/index'))
const Publish = lazy(() => import('@/pages/Publish/index'))

// 配置路由实例
const router = createBrowserRouter([
  {
    path: "/",
    element: <AuthRoute><Layout /></AuthRoute>,
    children: [
      {
        index: true,
        element: <Suspense fallback={'加载中'}><Home /></Suspense>
      },
      {
        path: "/article",
        element: <Suspense fallback={'加载中'}><Article /></Suspense>
      },
      {
        path: "/publish",
        element: <Suspense fallback={'加载中'}><Publish /></Suspense>
      }
    ]
  },
  {
    path: "/login",
    element: <Login />
  }
])

export default router